/*

	InputDevice.h
	
	Device object for managing user input.
	Used in conjunction with an event
	manager to register input events.
	
	Written by Sigurd Suhm 2009

*/

#ifndef _INPUTDEVICE_H
#define _INPUTDEVICE_H

// Includes
#include <SDL/SDL.h>

#include "EventHandler.h"

// Maximum number of mouse buttons
#define MOUSE_BUTTONS_MAX 5

namespace EraAstral
{
	namespace core
	{
		// Structure for keyboard data
		typedef struct
		{
			// Key state values
			bool keys[SDLK_LAST];
			// Key modifier
			SDLMod mod;
		} KeyboardData;
		
		// Struct for mouse data
		typedef struct
		{
			// Absolute mouse position
			int position[2];
			// Mouse button state values
			bool buttons[MOUSE_BUTTONS_MAX];
			// Mouse wheel absolute value
			float wheel;
		} MouseData;
	
		// Input device object definition
		class InputDevice : public IHasEvents
		{
			private:
				// Current and previous input states
				struct InputState
				{
					// Keyboard state
					KeyboardData keyboard;
					// Mouse state
					MouseData mouse;
				} *states;
				// Index of the current input state
				int curStateIndex;
				
				// Utility method for resetting an input state
				void ResetInputState(InputState *state);
		
			public:
				// Default constructor
				InputDevice();
				// Default destructor
				~InputDevice();
				
				// Notifies the input device that a new frame has started
				void NotifyNewFrame();
				
				// Override from IHasEvents
				void ProcessEventSignal(const Event *event);
				
				// Check if a key is down
				bool IsKeyDown(SDLKey keyCode);
				// Check if a key is up
				bool IsKeyUp(SDLKey keyCode);
				// Check if a key was down last frame
				bool WasKeyDown(SDLKey keyCode);
				// Check if a key was up last frame
				bool WasKeyUp(SDLKey keyCode);
				
				// Get X component of mouse position
				int		GetMouseX() const;
				// Get Y component of mouse position
				int		GetMouseY() const;
		};
	}
}

#endif		// _INPUTDEVICE_H
